package com.ls.socketio.controller;

import com.corundumstudio.socketio.SocketIOServer;
import com.ls.socketio.bean.*;
import com.ls.socketio.service.WebService;
import com.ls.socketio.view.BuildInfoView;
import com.ls.socketio.view.HotelInfoView;
import com.ls.socketio.view.LayerInfoView;
import com.ls.socketio.view.RoomInfoView;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @author liShan
 * @date 2019/9/3 11:11
 */
@RestController
@RequestMapping("/web")
@Log
public class WebController {

    @Resource
    private WebService webService;

    /**
     * 查询酒店的基本信息
     * @return 酒店的基本信息
     */
    @GetMapping("/hotel")
    public HotelInfoView findHotels(){
        return new HotelInfoView(2000, "查询成功", webService.findHotels());
    }

    /**
     * 添加酒店
     * @param hotelInfo 酒店信息
     * @return 添加结果
     */
    @PostMapping("/hotel/add")
    public HotelInfoView addHotel(@RequestBody HotelInfo hotelInfo){
        webService.addHotel(hotelInfo);
        return new HotelInfoView(2000, "添加成功");
    }

    /**
     * 添加酒店栋数
     * @param buildInfo 酒店栋数
     * @return 添加结果
     */
    @PostMapping("/build/add")
    public BuildInfoView addBuild(@RequestBody BuildInfo buildInfo){
        webService.addBuild(buildInfo);
        return new BuildInfoView(2000, "添加成功");
    }

    /**
     * 添加酒店栋数楼层
     * @param layerInfo 酒店栋数楼层
     * @return 添加结果
     */
    @PostMapping("/layer/add")
    public LayerInfoView addLayer(@RequestBody LayerInfo layerInfo){
        webService.addLayer(layerInfo);
        return new LayerInfoView(2000, "添加成功");
    }

    /**
     * 添加酒店栋数楼层房间
     * @param roomInfo 酒店栋数楼层房间
     * @return 添加结果
     */
    @PostMapping("/room/add")
    public RoomInfoView addRoom(@RequestBody RoomInfo roomInfo){
        System.err.println(roomInfo.toString());
        // webService.addRoom(roomInfo);
        return new RoomInfoView(2000, "添加成功");
    }

    /**
     * 向盒子发送命令
     * @return 处理结果
     */
    @PostMapping("/send/box")
    public RoomInfoView sendBox(){
        return webService.sendBox();
    }

    /**
     * 保存房间的环境参数
     * @param roomInfo 房间的基本信息
     * @return 执行结果
     */
    @PostMapping("/room/env/add")
    public RoomInfoView envAdd(@RequestBody RoomInfo roomInfo){
        System.err.println(roomInfo.toString());
        return new RoomInfoView(2000, "添加成功");
    }

    /**
     * 保存房间的状态
     * @param roomInfo 房间的基本信息
     * @return 执行结果
     */
    @PostMapping("/room/status/add")
    public RoomInfoView statusAdd(@RequestBody RoomInfo roomInfo){
        log.info(roomInfo.toString());
        webService.statusAdd(roomInfo);
        return new RoomInfoView(2000, "添加成功");
    }

}
